const mssql = require("mssql");
const conf = {
  user: "sa",
  password: "Prm@2020",
  server: "PMC-1469-PC2.prmeasure.com",
  database: "PMC",
  port: 1433,
  options: {
    encrypt: false, // Use this if you're on Windows Azure
    enableArithAbort: false,
  },
  pool: {
    min: 0,
    max: 10,
    idleTimeoutMillis: 3000,
  },
};
/**
 * 原生查询
 * @param {sql语句} strsql
 * @param {where参数对象} params
 * @returns 返回所有结果对象
 */
var query = function (strsql) {
  return new Promise(function (resolve, reject) {
    mssql
      .connect(conf)
      .then(function () {
        var ser = new mssql.Request();
        ser
          .query(strsql)
          .then(function (data) {
            resolve(data);
          })
          .catch(function (err) {
            reject(conf.debug ? err : err.code);
          });
      })
      .catch(function (err) {
        reject(conf.debug ? err : err.code);
      });
  }).catch((error) => {
    console.log(error);
  });
};

module.exports = query;
